# -*- coding: utf-8 -*-
from django import template
from datetime import timedelta
from a115 import dateutils

register = template.Library()

@register.filter
def prevDate(value):
	return value - timedelta(days=1)

@register.filter
def nextDate(value):
	return value + timedelta(days=1)

@register.filter
def bgDate(value):
	return dateutils.bg_date(value) or ""

@register.filter
def bgDateFull(value):
	return dateutils.bg_date_full(value) or ""

@register.filter
def bgDateShort(value):
	return dateutils.bg_date_short(value) or ""

@register.filter
def weekOf(value):
	sw = dateutils.start_week(value)
	ew = dateutils.end_week(value)
	return "%s - %s" % (dateutils.date2bg(sw), dateutils.date2bg(ew))

NTH_D = {0:'т',1:'в',2:'р',3:'т',4:'т',5:'т',6:'т',7:'м',8:'м',9:'т'}
NTH_G = {'N':'о', 'M':'и', 'F':'а'}
@register.filter
def bgNth(value, gender="N"):
	try:
		suffix = NTH_D[int(str(value)[-1])] + NTH_G[gender]
	except:
		return ""
	if value==0:
		suffix = 'в' + NTH_G[gender]
	return "%s-%s" % (value, suffix)
